﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Orpheus.Analyzer
{
    public class NoteNamingUtils
    {
        private static readonly string[] SharpedNames =
            {
                "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"
            };

        private static readonly string[] FlatedNames =
            {
                "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"
            };

        public static string GetNoteName(Note note, bool useSharps = true)
        {
            string noteName = useSharps ? SharpedNames[note.IndexInOctave] : FlatedNames[note.IndexInOctave];

            return noteName + ((int) note.Octave);
        }

        public static string GetNameOfNoteGroup(NoteGroup group, bool useSharps = true)
        {
            StringBuilder b = new StringBuilder();
            foreach (var note in group.Notes)
            {
                b.AppendFormat("{0} ", GetNoteName(note));
            }

            return b.ToString().Trim();
        }
    }
}
